<html>
<head>
    <title>机构管理列表</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="../../static/bootstrap/js/jquery-3.4.1.min.js" type="text/javascript"></script>
    <script src="../../static/bootstrap/js/static-resources.js"></script>
<script type="text/javascript">

    $(function () {
        $(".footerPage").load("../footer.html");
        let DEFAULT_DATA_MODEL = {
            "dutyCode":"",
            "dutyName":"",
            "legalOrgCode":"",
            "orderId":"",
            "dutyType":"",
            "memo":"",
            "orgId":"",
            "dutyLevel":"",
            "dutyParentCode":"",
            "createTime":"",
            "createUser":"",
            "lastUpdateUser":"",
            "lastUpdateTime":"",
            "status":"",
            "createOrgCode":"",
            "orgCode":"",
        };
        new Vue({
            el : '#app',
            mixins: [window.$DEFAULT_MIXIN],
            data: {
                queryParam: {
                    dutyCode: "",
                    dutyName: "",
                    status:"",
                },
                pageInfo: {
                    page: 1,
                    size: 10,
                    total: 0
                },
                list:[],
                selected: null,

                show: false,
                readonly: false,
                loading: false,
                modelTitle:"",
                dataObj: {},
                opType: "",
            },
            watch:{
                opType(val, old){
                    if (val == "add") {
                        this.modelTitle = "机构管理新增";
                        console.log("this.show:"+this.show)
                        this.show = !this.show;
                        this.readonly = false;
                        this.dataObj = $.extend({}, DEFAULT_DATA_MODEL);
                    } else if (val == "update") {
                        this.modelTitle = "机构管理修改";
                        this.show = true;
                        this.readonly = false;
                        this.dataObj = $.extend({}, this.selected);
                    } else if (val == "view") {
                        this.modelTitle = "机构管理详情";
                        this.show = true;
                        this.readonly = true;
                        this.dataObj = $.extend({}, this.selected);
                    }
                }
            },
            computed:{
                paths(){
                    return [
                        {text: '首页', href: '/index.html'},
                        {text: '系统设置', href: '#'},
                        {text: '组织机构', href: '#'},
                        {text: '机构管理', href: 'admin/SDutyList.html'},
                    ]
                },
                fields(){
                    return [
                        {key: 'dutyCode', label:'岗位代码', sortable: false},
                        {key: 'dutyName', label:'岗位名称', sortable: false},
                        {key: 'legalOrgCode', label:'机构法人代码', sortable: false},
                        {key: 'orderId', label:'排序字段', sortable: false,},
                        {key: 'dutyType', label:'类型', sortable: false},
                        {key: 'memo', label:'备注', sortable: false},
                        {key: 'orgId', label:'组织号', sortable: false},
                        {key: 'dutyLevel', label:'岗位层级', sortable: false},
                        {key: 'dutyParentCode', label:'上级岗位号', sortable: false,},
                        {key: 'createTime', label:'创建日期', sortable: false,},
                        {key: 'createUser', label:'创建人', sortable: false,},
                        {key: 'lastUpdateUser', label:'最后修改人', sortable: false,},
                        {key: 'lastUpdateTime', label:'最后修改日期', sortable: false,},
                        {key: 'status', label:'状态', sortable: false,},
                        {key: 'createOrgCode', label:'创建人所属机构', sortable: false,},
                        {key: 'orgCode', label:'机构代码', sortable: false,},
                    ]
                },
                STD_PUB_YN(){
                    return STD_PUB_YN;
                },
                STD_ORG_LEVEL(){
                    return STD_ORG_LEVEL;
                }
            },
            methods:{
                onRowSelected(items){
                    this.selected = items[0];
                },
                submitQry(page){
                    if (page == true) {
                        this.pageInfo.page = 1;
                    }
                    let self = this;
                    JLEUtil.requestForm("api/s/dutys", "POST", null, $.extend({}, self.queryParam, self.pageInfo),
                        function(data, textStatus, jqXHR){
                            self.list = data.rows;
                            self.pageInfo.total = data.total;
                        },
                        function(jqXHR, textStatus, errorThrown){

                        });
                },
                resetContent(){
                    this.queryParam.dutyCode = "";
                    this.queryParam.dutyName = "";
                    this.queryParam.status = "";
                },
                toAddPage(){
                    this.$bvModal.show('bv-modal-example');
                    this.opType = "add";
                },
                toModifyRecord(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    this.$bvModal.show('bv-modal-example');
                    this.opType = "update";
                },
                delRecord(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    if ('0' == this.selected.state) {
                        this.$bvToast.toast(`${this.selected.dutyName}，已注销，勿重复操作！`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    let self = this;
                    this.$bvModal.msgBoxConfirm(`你确定要删除【${this.selected.dutyName}】这个岗位?`, {
                        title: '删除提示',
                        size: 'sm',
                        buttonSize: 'sm',
                        okVariant: 'success',
                        headerClass: 'p-2 border-bottom-0',
                        footerClass: 'p-2 border-top-0',
                        cancelTitle: "取消",
                        okTitle: "确定",
                        centered: true
                    }).then(value => {
                        if (!value) return;
                    JLEUtil.request("api/s/duty", "DELETE", null, { dutyCode : this.selected.dutyCode},
                        function(data, textStatus, jqXHR){
                            self.$bvToast.toast(`${self.selected.dutyName}，删除成功！`, {
                                title: '提示 ',
                                toaster: 'b-toaster-top-center',
                                solid: true
                            });
                            self.submitQry(true);
                        },
                        function(jqXHR, textStatus, errorThrown){

                        });
                })
                },
                toViewPage(){
                    if (!this.selected) {
                        this.$bvToast.toast(`请选择一行数据`, {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                        return;
                    }
                    this.$bvModal.show('bv-modal-example');
                    this.opType = "view";
                },
                saveInfo(){

                    let requestOptions = {
                        url : "api/s/duty",
                        type : "POST",
                        dataObj: this.dataObj,
                        success: (data)=>{
                        this.$bvToast.toast(data.message, {
                        title: '提示 ',
                        toaster: 'b-toaster-top-center',
                        solid: true
                    });
                    this.loading = false;
                    this.closeModel();
                    this.submitQry();
                },
                    error: (jqXHR, textStatus, errorThrown)=>{
                        this.loading = false;
                        this.$bvToast.toast("提交失败", {
                            title: '提示 ',
                            toaster: 'b-toaster-top-center',
                            solid: true
                        });
                    }
                };
                    if (this.opType == "add") {
                        requestOptions.type = "POST";
                    } else if (this.opType == "update") {
                        requestOptions.type = "PUT";
                    }

                    this.loading = true;
                    let self = this;
                    this.$refs.form.validate().then(success => {
                        if (!success) {
                        this.loading = false;
                        return;
                    }
                    JLEUtil.request(requestOptions.url, requestOptions.type, null,
                        requestOptions.dataObj,
                        requestOptions.success,
                        requestOptions.error
                    );
                });
                },
                closeModel(){
                    this.show = false;
                    this.modelData = {};
                    this.opType = "";
                }
            },
            mounted(){
                this.submitQry(true);
            }
        })
    });

</script>
</head>
<body>
<div class="headerPage"></div>
<div id="app">
    <div class="container-fluid mt-3" >
        <div class="row">
            <div class="col-sm-12 search-box">
                <form role="form" id="formData" style="text-align: right" class="row">
                    <div class="form-group col-sm-3">
                        <b-form-group  label-cols="3" label-cols-lg="4" label="岗位代码：" >
                            <b-form-input size="sm" v-model="queryParam.dutyCode"></b-form-input>
                        </b-form-group>
                    </div>
                    <div class="form-group col-sm-3">
                        <b-form-group label-cols="3" label-cols-lg="4" label="岗位名称：" >
                            <b-form-input size="sm" v-model="queryParam.dutyName"></b-form-input>
                        </b-form-group>
                    </div>
                    <div class="form-group col-sm-3">
                        <b-form-group label-cols="3" label-cols-lg="2" label="状态：" >
                            <b-form-input size="sm" v-model="queryParam.status"></b-form-input>
                        </b-form-group>
                    </div>
                    <div class="control-group col-sm-3">
                        <div class="text-center">
                            <b-button size="xl" variant="primary" @click="submitQry(true)">&nbsp;&nbsp;查&nbsp;&nbsp;询&nbsp;&nbsp;</b-button>
                            <b-button variant="secondary" @click="resetContent">&nbsp;&nbsp;重&nbsp;&nbsp;置&nbsp;&nbsp;</b-button>
                        </div>
                    </div>
                </form>
                <div class="row"></div>
                <!-- table -->
            </div>
            <div class="form-group col-sm-12 ">
                <div class="text-left">
                    <b-button variant="primary" @click="toAddPage">&nbsp;&nbsp;新&nbsp;&nbsp;增&nbsp;&nbsp;</b-button>
                    <b-button class="b-button" variant="primary" @click="toModifyRecord">&nbsp;&nbsp;修&nbsp;&nbsp;改&nbsp;&nbsp;</b-button>
                    <b-button variant="primary" @click="delRecord">&nbsp;&nbsp;删&nbsp;&nbsp;除&nbsp;&nbsp;</b-button>
                    <b-button variant="primary" @click="toViewPage">&nbsp;&nbsp;查&nbsp;&nbsp;看&nbsp;&nbsp;</b-button>
                </div>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <!-- table start -->
        <b-table responsive hover selectable bordered fixed striped small
                 show-empty empty-text="查询列表为空"
                 @row-selected="onRowSelected"
                 selected-variant="primary"
                 select-mode="single" :fields="fields" :items="list" >
            <template v-slot:table-colgroup="scope">
                <col
                        v-for="field in scope.fields"
                        :key="field.key"
                        :style="{ width: '180px' }"
                >
            </template>
            <template v-slot:cell()="data" >
                <div class="text-truncate">{{ data.value }}</div>
            </template>
        </b-table>
        <div class="float-right">
            <b-pagination
                    v-model="pageInfo.page"
                    :total-rows="pageInfo.total"
                    :per-page="pageInfo.size"
                    @change="submitQry"
            ></b-pagination>
        </div>
        <!-- table end -->
    </div>

    <!--<b-modal  v-model="show" :title="modelTitle" size="xl"-->
              <!--scrollable-->
              <!--no-close-on-backdrop-->
              <!--hide-header-close-->
              <!--no-close-on-esc>-->
        <b-modal  v-model="show" id="bv-modal-example" :title="modelTitle" size="xl"
                  scrollable
                  no-close-on-backdrop
                  no-close-on-esc>
        <b-container fluid >
            <validation-observer ref="form">
                <form role="form" >
                    <div class="row">
                        <div class="col-sm-6">
                            <validation-provider name="dutyCode" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="岗位代码" label-cols-sm="4" label-align-sm="right">
                                    <b-form-input type="text" v-model="dataObj.dutyCode" :readonly="readonly"
                                                  :state="getValidationState(validationContext)"
                                                  name="dutyCode" placeholder="岗位代码"></b-form-input>
                                    <b-form-invalid-feedback >岗位代码不能为空</b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <validation-provider name="dutyName" :rules="{ required: true }" v-slot="validationContext">
                                <b-form-group label="岗位名称" label-cols-sm="4" label-align-sm="right">
                                    <b-form-input type="text" v-model="dataObj.dutyName"
                                                  :state="getValidationState(validationContext)"
                                                  name="dutyName" placeholder="岗位名称"  :readonly="readonly"></b-form-input>
                                    <b-form-invalid-feedback >岗位名称不能为空</b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="机构法人代码" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.legalOrgCode" name="legalOrgCode"  placeholder="机构法人代码"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="排序字段" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.orderId" name="orderId"  placeholder="排序字段"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="类型" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.dutyType" name="dutyType"  placeholder="类型"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="备注" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.memo" name="memo"  placeholder="备注"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="组织号" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.orgId" name="orgId"  placeholder="组织号"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="岗位层级" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.dutyLevel" name="dutyLevel"  placeholder="岗位层级"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="上级岗位号" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.dutyParentCode" name="dutyParentCode"  placeholder="上级岗位号"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="创建日期" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.createTime" name="createTime"  placeholder="创建日期"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="创建人" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.createUser" name="createUser"  placeholder="创建人"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                       
                        <div class="col-sm-6">
                            <b-form-group label="最后修改人" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.lastUpdateUser" name="lastUpdateUser"  placeholder="最后修改人"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="最后修改日期" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.lastUpdateTime" name="lastUpdateTime"  placeholder="最后修改日期"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                        <div class="col-sm-6">
                            <b-form-group label="状态" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.status" name="status"  placeholder="状态"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div><div class="col-sm-6">
                            <b-form-group label="创建人所属机构" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.createOrgCode" name="status"  placeholder="创建人所属机构"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div><div class="col-sm-6">
                            <b-form-group label="机构代码" label-cols-sm="4" label-align-sm="right">
                                <b-form-input type="text" v-model="dataObj.orgCode" name="status"  placeholder="机构代码"  :readonly="readonly"></b-form-input>
                            </b-form-group>
                        </div>
                    </div>
                </form>
            </validation-observer>
        </b-container>
        <template v-slot:modal-footer>
            <div class="control-group col-sm-12">
                <div class="text-center">
                    <b-button variant="primary" @click="saveInfo" :disabled="loading">
                        <div v-if="loading">
                            <b-spinner small></b-spinner>
                            保存中...
                        </div>
                        <span v-else="loading">保存</span>
                    </b-button>
                    <b-button variant="secondary" @click="closeModel" :disabled="loading">返回</b-button>
                </div>
            </div>
        </template>
    </b-modal>
</div>
<div class="footerPage"></div>
</body>
</html>
